From 6d8ee3e7d579493e0324441f89875b37d5520ee3 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Sun, 6 Dec 2020 13:41:20 -0600 Subject: [PATCH] Move integration tests into their own file --- tests/test_pgwui_server.py | 40 ++---------------------- tests/test_pgwui_server_integration.py | 42 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 tests/test_pgwui_server_integration.py diff --git a/tests/test_pgwui_server.py b/tests/test_pgwui_server.py index 48d6d86..e8532b7 100644 --- a/tests/test_pgwui_server.py +++ b/tests/test_pgwui_server.py @@ -35,12 +35,8 @@ import pgwui_server.checkset import pgwui_server.pgwui_server as pgwui_server -# Constants - -TEST_SETTINGS = { - 'pgwui.validate_hmac': 'False', - 'pgwui.dry_run': 'False', -} +# Mark all tests with "unittest" +pytestmark = pytest.mark.unittest # Use contextlib.AbstractContextManager for Python >= 3.6 @@ -80,7 +76,6 @@ mock_add_routes = testing.make_mock_fixture( # dot_to_multiline_setting() -@pytest.mark.unittest def test_dot_to_multiline_setting_new(mock_parse_assignments): '''Adds a new dict and puts the settings in it ''' @@ -98,7 +93,6 @@ def test_dot_to_multiline_setting_new(mock_parse_assignments): assert settings == expected -@pytest.mark.unittest def test_dot_to_multiline_setting_old(mock_parse_assignments): '''Extends an existing dict in the settings ''' @@ -123,7 +117,6 @@ mock_dot_to_multiline_setting = testing.make_mock_fixture( # component_setting_into_dict() -@pytest.mark.unittest def test_component_setting_into_dict_no_checker( mock_dot_to_multiline_setting): '''When there's no checker nothing is done @@ -136,7 +129,6 @@ def test_component_setting_into_dict_no_checker( assert errors == [] -@pytest.mark.unittest def test_component_setting_into_dict_checker( mock_dot_to_multiline_setting): '''When there's a checker its result is appended to the errors @@ -159,7 +151,6 @@ mock_component_setting_into_dict = testing.make_mock_fixture( # dot_to_dict() -@pytest.mark.unittest def test_dot_to_dict(): '''Removes pgwui.* settings, replaces them with a dict entry ''' @@ -183,7 +174,6 @@ mock_dot_to_dict = testing.make_mock_fixture( # parse_multiline_assigments() -@pytest.mark.unittest def test_parse_multiline_assignments_str(): '''Appends key/value string tuples and when there's no "=", and more than just whitespace, a list is the result @@ -208,7 +198,6 @@ mock_parse_multiline_assignments = testing.make_mock_fixture( # parse_assignments() -@pytest.mark.unittest def test_parse_assignments_str(mock_parse_multiline_assignments): '''Calls parse_multiline_assignments''' lines = ('key1 = value1\n' # whitespace around = is ignored @@ -221,7 +210,6 @@ def test_parse_assignments_str(mock_parse_multiline_assignments): mock_parse_multiline_assignments.assert_called_once() -@pytest.mark.unittest def test_parse_assignments_dict(mock_parse_multiline_assignments): '''Returns key value tuples. ''' @@ -240,7 +228,6 @@ mock_parse_assignments = testing.make_mock_fixture( # setting_into_dict() -@pytest.mark.unittest def test_setting_into_dict_unknown( mock_component_setting_into_dict, mock_dot_to_dict, @@ -252,7 +239,6 @@ def test_setting_into_dict_unknown( assert errors == [] -@pytest.mark.unittest def test_setting_into_dict_bad( mock_parse_assignments, mock_component_setting_into_dict, @@ -268,7 +254,6 @@ def test_setting_into_dict_bad( assert isinstance(errors[0], common_ex.UnknownSettingKeyError) -@pytest.mark.unittest def test_setting_into_dict_good( mock_component_setting_into_dict, mock_dot_to_dict, @@ -285,7 +270,6 @@ def test_setting_into_dict_good( assert errors == [] -@pytest.mark.unittest def test_setting_into_dict_multiline( mock_component_setting_into_dict, mock_dot_to_dict, @@ -303,7 +287,6 @@ def test_setting_into_dict_multiline( assert errors == [] -@pytest.mark.unittest def test_setting_into_dict_plugin_component( mock_component_setting_into_dict, mock_dot_to_dict, @@ -329,7 +312,6 @@ mock_setting_into_dict = testing.make_mock_fixture( # dictify_settings() -@pytest.mark.unittest def test_dictify_settings(mock_find_pgwui_check_settings, mock_setting_into_dict, mock_validate_setting_values, @@ -374,7 +356,6 @@ def assert_exit1(): return run -@pytest.mark.unittest def test_exit_reporting_errors_logged( assert_exit1, monkeypatch, caplog, capsys): '''All errors are logged at ERROR, and a extra one at CRITICAL @@ -394,7 +375,6 @@ def test_exit_reporting_errors_logged( assert levels[-1] == logging.CRITICAL -@pytest.mark.unittest def test_exit_reporting_errors_printed( assert_exit1, monkeypatch, capsys): '''First and last (the extra) errors are printed on stderr @@ -419,7 +399,6 @@ mock_exit_reporting_errors = testing.make_mock_fixture( # add_default_settings() -@pytest.mark.unittest def test_add_default_settings(): '''The default settings are added ''' @@ -435,7 +414,6 @@ mock_add_default_settings = testing.make_mock_fixture( # exit_on_invalid_settings() -@pytest.mark.unittest def test_exit_on_invalid_settings_invalid( monkeypatch, mock_add_default_settings, mock_dictify_settings, @@ -455,7 +433,6 @@ def test_exit_on_invalid_settings_invalid( assert mock_exit_reporting_errors.called -@pytest.mark.unittest def test_exit_on_invalid_settings_valid( mock_add_default_settings, mock_dictify_settings, mock_exit_reporting_errors): @@ -472,7 +449,6 @@ mock_exit_on_invalid_settings = testing.make_mock_fixture( # autoconfigurable_components() -@pytest.mark.unittest def test_autoconfiguable_components_no_autoconfig(): '''When the settings have no pgwui.autoconfigure return an empty list ''' @@ -484,7 +460,6 @@ def test_autoconfiguable_components_no_autoconfig(): assert result == [] -@pytest.mark.unittest def test_autoconfigurable_components_log_info(caplog): '''When pyramid.include is in the settings an INFO message is logged ''' @@ -503,7 +478,6 @@ def test_autoconfigurable_components_log_info(caplog): assert level == logging.INFO -@pytest.mark.unittest def test_autoconfigurable_components_components_returned(): '''The suppiled components are returned when autoconfigure is True ''' @@ -521,7 +495,6 @@ mock_autoconfigurable_components = testing.make_mock_fixture( # apply_component_defaults() -@pytest.mark.unittest def test_apply_component_defaults(monkeypatch, caplog, mock_autoconfigurable_components, mock_add_routes): @@ -553,7 +526,6 @@ mock_apply_component_defaults = testing.make_mock_fixture( # pgwui_server_config() -@pytest.mark.unittest def test_pgwui_server_config( mock_find_pgwui_components, mock_apply_component_defaults, mock_exit_on_invalid_settings): @@ -567,7 +539,6 @@ def test_pgwui_server_config( # main() -@pytest.mark.unittest def test_main(monkeypatch): '''Returns a wsgi app''' monkeypatch.setattr(pgwui_server, 'pgwui_server_config', @@ -575,10 +546,3 @@ def test_main(monkeypatch): result = pgwui_server.main({}) assert result == 'wsgi_app' - - -# Integration tests -@pytest.mark.integrationtest -def test_main_integrated(): - '''Does not raise errors or warnings''' - pgwui_server.main({}, **TEST_SETTINGS) diff --git a/tests/test_pgwui_server_integration.py b/tests/test_pgwui_server_integration.py new file mode 100644 index 0000000..058f0e6 --- /dev/null +++ b/tests/test_pgwui_server_integration.py @@ -0,0 +1,42 @@ +# Copyright (C) 2018, 2019, 2020 The Meme Factory, Inc. +# http://www.karlpinc.com/ + +# This file is part of PGWUI_Server. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License +# as published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with this program. If not, see +# . +# + +# Karl O. Pinc + +import pytest + +import pgwui_server.pgwui_server as pgwui_server + + +# Mark all tests as "integrationtest" +pytestmark = pytest.mark.integrationtest + +# Constants + +TEST_SETTINGS = { + 'pgwui.validate_hmac': 'False', + 'pgwui.dry_run': 'False', +} + + +# Integration tests +def test_main_integrated(): + '''Does not raise errors or warnings''' + pgwui_server.main({}, **TEST_SETTINGS) -- 2.34.1